import os

def tree():
    path = input("请输入路径：")
    if not os.path.isdir(path):
        print("无效的路径")
        return

    _tree(path)

def _tree(path, level=0):
    files = os.listdir(path)
    for file in sorted(files):
        print("|   " * level + "|-- " + file)
        file_path = os.path.join(path, file)
        if os.path.isdir(file_path):
            _tree(file_path, level + 1)

tree()
